package com.hualan.controller;

import com.hualan.pojo.PageResult;
import com.hualan.pojo.Result;
import com.hualan.pojo.Welfare;
import com.hualan.service.WelfareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/welfare")
public class WelfareController {
    @Autowired
    private WelfareService welfareService;

    @GetMapping("/search")
    public Result queryAllWelfare(String title,@RequestParam (defaultValue = "1") Integer page,@RequestParam  (defaultValue = "10") Integer pageSize) {
        PageResult pageResult = welfareService.queryAllWelfare(title, page, pageSize);
        return Result.success(pageResult);
    }

    @PostMapping("/add")
    public Result addWelfare(@RequestBody Welfare welfare) {
        Result result = welfareService.addWelfare(welfare);
        return result;
    }

    @PutMapping("/update")
    public Result updateWelfare(@RequestBody Welfare welfare) {
        Result result = welfareService.updateWelfare(welfare);
        return result;
    }

    @PutMapping("/delete")
    public Result deleteWelfare(@RequestBody List<Integer> ids) {
        Result result = welfareService.deleteWelfare(ids);
        return result;
    }

}
